<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragrma", "no-cache");
    response.setDateHeader("Expires", 0);
    Long resid = Long.parseLong(request.getParameter("id"));
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>real-time-process</title>
	<%@ include file="../include/common.jsp"%>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/portal.css" />
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/style/default/bsm/perf/listPage.css" />
  	<script type="text/javascript" src="/bsm/resources/charts/FusionCharts.js"></script>
  	<script type="text/javascript" src="${pageContext.request.contextPath}/resources/charts/FusionCharts.jqueryplugin.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/common/Xslider.js"></script>
 	<script type="text/javascript" src="${pageContext.request.contextPath}/jsp/performance/data/RTLED.js"></script>		
  	<style type="text/css">
  		body{text-align: left;}
  		.basicInfo{width:99%;clear: both;}
    	span{height:24px;line-height: 24px;}
    	.col-main-basic{height:24px;border:1px solid #afcbdf;}
		.col-main-span-l{width:7%;min-width:40px;background: #dfe8f9;height:24px;line-height: 24px;float:left;white-space:nowrap;}
		.col-main-span-r{width:25%;min-width:40px;text-align: left;padding-left:10px;float:left;border-left:0px;white-space:nowrap;}
	</style>
  	<script type="text/javascript">
  		var resTypeId = '';
	  	$(function(){
	  		initRealTimeChart();
	  		$.ajax({
				url : 'real-time!getResType.action', 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>
				},
				success : function(data) {
					resTypeId = data;
			  		//linux
			  		if(resTypeId == '1205020200000'){
			  			//平均进程使用内存
				  		initchartMen(4,'120502020000002');
				  		//平均进程占用CPU
				  		initchartCpu(4,'120502020000001');
			  		}else{
			  		//平均进程使用内存
				  		initchartMen(4,'120502010000003');
				  		//平均进程占用CPU
				  		initchartCpu(4,'120502010000002');
			  		}
			  		//基本信息
			  		initBasicInfo(resTypeId);
			  		pieDay(0);
					pieDay(7);
					pieDay(30);
				}
			});
	  	})
	  	var cpuVRealLed;
		function initRealTimeChart(){
				cpuVRealLed =  new FusionCharts("${pageContext.request.contextPath}/resources/charts/VLED.swf", "cpuVled11", "100%", "100%", "0", "1" );
			    cpuVRealLed.setXMLData(RTString);
		        cpuVRealLed.render("cpuVReal");
		}
		function freshMemData(data){
			var cpuVLEDV = getChartFromId("cpuVled11");
			var cpuHisLineV = getChartFromId("cpuHisLine11");
			cpuVLEDV.feedData("&value="+data);
		}
		function initBasicInfo(resTypeId){
			var propIds = '';
			if(resTypeId == '1205020200000'){
				propIds = 'attr_120502020000002,prop_120502020000003,prop_120502020000005,prop_120502020000001';
			}else{
				propIds = 'attr_120502010000001,prop_120502010000004,prop_120502010000001,prop_120502010000002';
			}
			$.ajax({
				url : 'real-time!getBaseInfo.action', 
				type : 'POST',
				dataType : "json",
				data : {
					resId :<%=resid %>,
					propIds:propIds
				},
				success : function(data) {
					if(resTypeId == '1205020200000'){
						$('#attr_120502020000002').text(data.attr_120502020000002);
						$("#propname_120502020000003").css({"display":""});
						$("#prop_120502020000003").css({"display":""});
						$('#prop_120502020000003').text(data.prop_120502020000003+"  "+getStatus(data.prop_120502020000003));
						$('#prop_120502020000005').text(data.prop_120502020000005);
						setInterval("freshMemData("+data.prop_120502020000001+")");
					}else{
						$('#attr_120502020000002').text(data.attr_120502010000001);
						$("#propname_120502010000004").css({"display":""});
						$("#prop_120502010000004").css({"display":""});
						$('#prop_120502010000004').text(data.prop_120502010000004);
						$('#prop_120502020000005').text(data.prop_120502010000001);
						setInterval("freshMemData("+data.prop_120502010000002+")");
					}
				}
			});
		}
		function getStatus(status){
			if(status == 'S'){
				return "可中断的睡眠状态";
			}else if(status == 'R'){
				return "可执行状态";
			}else if(status == 'D'){
				return "不可中断的睡眠状态";
			}else if(status == 'T'){
				return "暂停状态或跟踪状态";
			}else if(status == 'Z'){
				return "退出状态";
			}else if(status == 'X'){
				return "退出状态,将被销毁";
			}else {
				return "";
			}
		}
	  	function pieDay(type){
			//为了和健康度查询数据共享 特加入以下参数
		  	 var beginDate ;
			 var endDate;
			 var currentDate = new Date();
			 if(type==0){
			 	beginDate = currentDate.getFullYear()+"-"+add_zero(currentDate.getMonth()+1)+"-"+add_zero(currentDate.getDate())+" "+"00:00:00";
			 	endDate = currentDate.getFullYear()+"-"+add_zero(currentDate.getMonth()+1)+"-"+add_zero(currentDate.getDate())+" "+add_zero(currentDate.getHours())+":"+add_zero(currentDate.getMinutes())+":00"
			 }
			 $.ajax({
				url : '${pageContext.request.contextPath}/resource/res-healthy!findResHealthData.action', 
				type : 'POST',
				dataType : "json",
				data : {
					id :'<%=resid %>',
					choose:type, //1：近24小时 7：近7天内 30：近一个月内 0：今天
					dimension:1, //1：时汇聚 2：日汇聚
					dateScope:beginDate+"|"+endDate
				},
				success : function(data) {
					 pieChartInit(data,type);
				}
			});
			
		}
	  	function add_zero(temp)
		{
			 if(temp<10) 
			 		return "0"+temp;
			 else 
			 		return temp;
		}
		function pieChartInit(data,type){
			 var title="";
			 var divId ="";
			 if(type==0){
			 	title="今天";
			 	divId="countTodayPie";
			 }else if(type==1){
			 	title="近24小时";
			 	divId="count24Pie";
			 }else if(type==7){
			 	title="近7天内";
			 	divId="count7Pie";
			 }else{
			 	title="近一个月内";
			 	divId="count1MonthPie";
			 }
			  			
			 var normal =0;
			 var minor = 0;
			 var warn  =0 ;
			 var major =0;
			 var critical=0;
			 var sum=0;
			 var val="";
			 
			 $.each(data,function(index,ob){
			 	var value = parseInt(ob.degree);
			 	sum=sum+value;
			 	if(value>=0&&value<=20){
			 		critical+=value;
			 	}else if(value>20&&value<=40){
			 		major+=value;
			 	}else if(value>40&&value<=60){
			 		warn+=value;
			 	}else if(value>60&&value<=80){
			 		minor+=value;
			 	}else{
			 		normal+=value;
			 	}
			 });
			 
			 var label =["正常","轻微","警告","重要","严重"];
			 var value =[normal,minor,warn,major,critical];
			 var colorArray =["94E75F","67B9E1","F0E267","F57100","DF0202"];
			 for(var i=0;i<5;i++){
			 	var v=value[i]/sum;
			 	val+="<set label='"+label[i]+"' value='"+(v.toFixed(4)*100)+"' isSliced='"+(i==3||i==label.length-1?1:0)+"' color='"+colorArray[i]+"' />";
			 }
			var str="";
			str+=" <chart caption='"+title+"' decimals='2'  enableSmartLabels='1' formatNumberScale='0' enableRotation='0' bgColor='99CCFF,FFFFFF' animation='1'   numbersuffix='%' pieSliceDepth='30' startingAngle='125' ";
			str+="    bgAlpha='65' >";
			str+=val;
			str+=" </chart>";
			var countTodayPie = new FusionCharts("${pageContext.request.contextPath}/resources/charts/Pie3D.swf?ChartNoDataText=没有数据",""+divId+"1", "99%", "100%", "0", "1"); 
			countTodayPie.setDataXML(str);		   
		    countTodayPie.render(divId);
		}
	  	function initchartMen(type,propId){	
	  		if(FusionCharts("chartMenId")){
	  			FusionCharts("chartMenId").dispose();
	  		}
			var chart = new FusionCharts("/bsm/resources/charts/MSSpline.swf", "chartMenId", "99%", "100%", "0", "0");
			$.ajax({
				url : 'prop-trend!createProcess.action', 
				type : 'POST',
				dataType : "json",
				data : {
					dimen:'1',
					trendtype:'0',
					timeSection:type,
					resId :<%=resid %>,
					beginDate:'',
					endDate:'',
					propIds:propId
				},
				success : function(data) {
					chart.setJSONData(data.value);
				}
				
			});
			chart.render("chartMen");
	  	}
	  	function initchartCpu(type,propId){	
	  		if(FusionCharts("chartCpuId")){
	  			FusionCharts("chartCpuId").dispose();
	  		}
			var chart = new FusionCharts("/bsm/resources/charts/MSSpline.swf", "chartCpuId", "99%", "100%", "0", "0");
			$.ajax({
				url : 'prop-trend!createProcess.action', 
				type : 'POST',
				dataType : "json",
				data : {
					dimen:'1',
					trendtype:'0',
					timeSection:type,
					resId :<%=resid %>,
					beginDate:'',
					endDate:'',
					propIds:propId
				},
				success : function(data) {
					chart.setJSONData(data.value);
				}
				
			});
			chart.render("chartCpu");
	  	}
	</script>
  </head>
  
  <body>
 
		<div class="basicInfo">
			<div class="col-main-basic" >
				<span class="col-main-span-l ">进程名称:</span><span class="col-main-span-r" id="attr_120502020000002"></span>
				<span class="col-main-span-l ">进程个数:</span><span class="col-main-span-r" id="prop_120502020000005"></span>
				<span class="col-main-span-l " style="display: none" id="propname_120502020000003">进程状态:</span><span class="col-main-span-r"  id="prop_120502020000003" style="display: none"></span> 
				<span class="col-main-span-l " style="display: none" id="propname_120502010000004">运行时长:</span><span class="col-main-span-r"  id="prop_120502010000004" style="display: none"></span> 
			</div>
		</div>
		<div class="col-r-main" style="height: 180px;width: 100%">
			<div class="col-v-rate-extra" style="width:50%;height: 100%;float: left;margin-left: 2px;">
				<h2 class="title-h2 m-0">平均进程使用CPU百分比</h2>
					<div id="cpuVReal" style="width: 20%;height:150px;float: left;"></div>
					<div id="chartCpu" style="width:80%;height:150px; float: left;">
					</div>
			</div>
			<div class="col-v-rate-extra" style="width:49%;float: right;height: 100%;">
				<h2 class="title-h2 m-0">平均进程使用内存大小</h2>
				<div id="chartMen" style="width:100%;height:150px; float: right;">
				</div>
			</div>
		</div>
		<div class="col-r-main" style="height: 280px;width: 100%">
			<h2 class="title-h2 m-0">健康度统计</h2>
			<div id="countTodayPie" class="col-v-rate-extra" style="width:33%;height:250px; float: left;">
		 	</div>
		 	<div id="count7Pie" class="col-v-rate-extra" style="width:33%;height:250px;float: left;">
		 	</div>
		 	<div id="count1MonthPie" class="col-v-rate-extra" style="width:33%;height:250px;float: left;">
		 	</div>
		</div>
		</body>
</html>
